<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>同一台MySQL服务器启动多个端口 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>同一台MySQL服务器启动多个端口</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/MySQL/">MySQL</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先安装二进制源码包的mysql</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装到初始化数据库的时候，因为是多个端口，所以要根据配置文件来初始化多个数据库。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;比如有2个端口</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;则要运行两次</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">./scripts/mysql_install_db --datadir=/home/mysql1 --user=mysql</div><div class="line">./scripts/mysql_install_db --datadir=/home/mysql2 --user=mysql</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line">[mysqld0]</div><div class="line">port = 3300</div><div class="line">socket = /tmp/mysql0.sock</div><div class="line">pid-file = /home/mysql0/localhost.localdomain0.pid</div><div class="line">datadir = /home/mysql0</div><div class="line"><span class="comment">#log = /data/mysql0/mysql0.log</span></div><div class="line">user = mysql</div><div class="line">skip-locking</div><div class="line">skip-name-resolve</div><div class="line"><span class="comment">#skip-bdb</span></div><div class="line"><span class="comment">#skip-innodb</span></div><div class="line">key_buffer = 128M</div><div class="line">max_allowed_packet = 1M</div><div class="line">table_cache = 864</div><div class="line">sort_buffer_size = 1M</div><div class="line">read_buffer_size = 512K</div><div class="line">read_rnd_buffer_size = 1M</div><div class="line">myisam_sort_buffer_size = 32M</div><div class="line">thread_cache_size = 16</div><div class="line">query_cache_size = 32M</div><div class="line">thread_concurrency = 8</div><div class="line"><span class="comment">#skip-networking</span></div><div class="line">wait_timeout=8</div><div class="line">max_connections=512</div><div class="line">max_connect_errors = 10000000</div><div class="line">max_user_connections=20</div><div class="line"><span class="comment">#slow_queries=/data/mysql0slowquer.sql</span></div><div class="line"><span class="comment">#log_slow_queries=/data/mysql0slowquer.sql</span></div><div class="line"><span class="comment">#long_query_time=3</span></div><div class="line"><span class="comment">#log-bin=mysql0-bin</span></div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">[mysqld1]</div><div class="line">port = 3301</div><div class="line">socket = /tmp/mysql1.sock</div><div class="line">pid-file = /home/mysql1/localhost.localdomain1.pid</div><div class="line">datadir = /home/mysql1</div><div class="line"><span class="comment">#log = /data/mysql1/mysql1.log</span></div><div class="line">user = mysql</div><div class="line">skip-locking</div><div class="line">skip-name-resolve</div><div class="line"><span class="comment">#skip-innodb</span></div><div class="line"><span class="comment">#skip-bdb</span></div><div class="line">key_buffer = 128M</div><div class="line">max_allowed_packet = 1M</div><div class="line">table_cache = 864</div><div class="line">sort_buffer_size = 1M</div><div class="line">read_buffer_size = 512K</div><div class="line">read_rnd_buffer_size = 1M</div><div class="line">myisam_sort_buffer_size = 32M</div><div class="line">thread_cache_size = 16</div><div class="line">query_cache_size = 32M</div><div class="line">thread_concurrency = 8</div><div class="line"><span class="comment">#skip-networking</span></div><div class="line">wait_timeout=8</div><div class="line">max_connections=512</div><div class="line">max_connect_errors = 10000000</div><div class="line">max_user_connections=20</div><div class="line"><span class="comment">#log_slow_queries=/data/mysql1slowquer.sql</span></div><div class="line"><span class="comment">#long_query_time=3</span></div><div class="line"><span class="comment">#log-bin=mysql1-bin</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把配置文件放在 /etc/my.cnf</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;启动mysql</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/mysql/bin/mysqld_multi start 0-1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里的0或1是根据配置文件中 <code>[mysqld0]</code> 来定的。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/MySQL/21. 同一台MySQL服务器启动多个端口/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
